//
//  XQPhotoCell.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/9/7.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "XQPhotoCell.h"

@interface XQPhotoCell ()
{
    
    UILabel *gifV;
    UIButton *pushBtn;
}

@end

@implementation XQPhotoCell

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self loadUI];
    }
    return self;
}

- (void)loadUI
{
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectZero];
    _imageV.contentMode = UIViewContentModeScaleAspectFill;
    _imageV.userInteractionEnabled = YES;
    _imageV.clipsToBounds = YES;
    _imageV.backgroundColor = [UIColor c3Color];
    [self.contentView addSubview:_imageV];
    
    gifV = [[UILabel alloc] init];
    gifV.text = @"GIF";
    gifV.backgroundColor = [UIColor blackColor];
    gifV.alpha = 0.7;
    gifV.textColor = [UIColor c3Color];
    gifV.font = [UIFont systemFontOfSize:15];
    gifV.textAlignment = NSTextAlignmentCenter;
    gifV.layer.cornerRadius = 15;
    gifV.layer.masksToBounds = YES;
    [self.contentView addSubview:gifV];
    
    pushBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    pushBtn.layer.cornerRadius = 25;
    pushBtn.layer.masksToBounds = YES;
    [pushBtn setImage:[UIImage imageNamed:@"home_t"] forState:UIControlStateNormal];
    [pushBtn setImage:[UIImage imageNamed:@"home_t"] forState:UIControlStateHighlighted];
//    [pushBtn setImageEdgeInsets:UIEdgeInsetsZero];
    pushBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [pushBtn addTarget:self action:@selector(pushBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:pushBtn];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.backgroundColor = [UIColor c3Color];
    if ([_plates integerValue] == 1)
    {
        _imageV.frame = self.contentView.bounds;
    }
    else if ([_plates integerValue] == 2)
    {
        _imageV.frame = CGRectMake(KSCREENWIDTH / 4, 0, KSCREENWIDTH / 2, self.height);
    }
//    else if ([_plates integerValue] == 3)
//    {
//        _imageV.frame = self.bounds;
//    }
    [_imageV sd_setImageWithURL:[NSURL URLWithString:_imgUrl]];
    if (_isGif)
    {
        gifV.hidden = NO;
    }
    else
    {
        gifV.hidden = YES;
    }
    gifV.size = CGSizeMake(50, 30);
    gifV.center = _imageV.center;
    
    if (_isT)
    {
        pushBtn.hidden = NO;
    }
    else
    {
        pushBtn.hidden = YES;
    }
    pushBtn.frame = CGRectMake(self.width - 50, self.height - 50, 50, 50);
}

- (void)pushBtnClick
{
    self.block();
}


@end
